package com.myway.common.ibe.domain.order;

import java.util.HashMap;

public enum TicketType {
	PAPER_TICKET("PT"), ELECTRONIC_TICKET("ET");

	/**
	 * Alias name. This is the name which will be stored in database.
	 */
	private final String alias;

	/**
	 * A hash map which keep all the ticket type enum with alias name as key.
	 */
	private static HashMap<String, TicketType> map;

	/**
	 * Construct the hash map at load time
	 */
	static {
		map = new HashMap<String, TicketType>();
		for (TicketType type : TicketType.values()) {
			map.put(type.alias, type);
		}
	}

	TicketType(String alias) {
		this.alias = alias;
	}

	@Override
	public String toString() {
		return this.alias;

	}

	/**
	 * Return a <code>TicketType</code> object holding the value of specified alias name
	 * 
	 * @param alias
	 *            the alias name of the type
	 * 
	 * @return a <code>TicketType</code> object holding the value represented by the alias name
	 *         argument
	 */
	public static TicketType valueOfAlias(String alias) {
		TicketType type = map.get(alias);

		if (type == null) {
			throw new IllegalArgumentException("Unknown ticket type alias [" + alias + "]");
		}

		return type;
	}

}